<?php
namespace traits;

use think\facade\Db;

trait modelTrait
{
    public static $model = null;

    public static function newInstance()
    {
        if (self::$model == null) {
            Db::setConfig(config('Mysql'));
            self::$model = Db::table(self::get_class_name());
        }
        return self::$model;
    }

    public static function get_class_name()
    {
        $class = get_called_class();
        $init = (int)strrpos($class, '\\');
        return strtolower(substr($class, ($init ? $init + 1 : 0)));
    }
}